﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using BUS;
using DTO;
using Telerik.Web;
using Telerik.Web.UI;

namespace TCV_WEB.Admin.Page
{
    public partial class User : System.Web.UI.Page
    {
        string _sErr = "";
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        private void LoadDataGrid()
        {

            try
            {
                DataTable dtb;
                BUS.UserControl user_control = new BUS.UserControl();

                dtb = user_control.GetAll(ref _sErr);
                RadGrid1.DataSource = dtb;
          //      RadGrid1.Rebind();
            }
            catch (Exception ex)
            {
                //         lblErr.Text = ex.Message;
            }

        }

        protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName.ToUpper() == "DELETE")
            {
                try
                {
                    Int32 inewsid = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString().Trim());
                    BUS.UserControl new_control = new BUS.UserControl();

                    new_control.Delete(inewsid);
                    RadGrid1.Rebind();
                }
                catch (System.Exception ex)
                {
                    //       lblErr.Text = ex.Message;
                }
            }
            if (e.CommandName.ToUpper() == "LOAD")
            {
                Int32 inewsid = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString().Trim());
                Session["userid"] = inewsid;
                Response.Redirect("~/Admin/Page/OrderUser.aspx");
            }
        }

     
        protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            //if (e.Item is GridDataItem && e.Item.DataItem != null)
            //{
            //    try
            //    {
            //        DataRow row = ((DataRowView)e.Item.DataItem).Row;
            //        Int32 ID = Convert.ToInt32(row["ID"]);
            //        BUS.UserControl newsCtrl = new BUS.UserControl();
            //        UserInfo newsInfo = newsCtrl.Get(ID, ref _sErr);
            //        Label proName = (Label)e.Item.FindControl("Sex");
            //        if (newsInfo.Sex == true)
            //            proName.Text = "Nam";
            //        else
            //            proName.Text = "Nữ";
            //    }
            //    catch (Exception ex)
            //    { }

            //}
        }

        protected void RadGrid1_NeedDataSource1(object sender, GridNeedDataSourceEventArgs e)
        {
            LoadDataGrid();
        }
    }
}
